package cn.hpclub.server.validator.admin;

import com.jfinal.core.Controller;
import com.jfinal.kit.StrKit;
import com.jfinal.validate.Validator;

import cn.hpclub.server.model.Broadband;

public class BroadbandValidator extends Validator {

	@Override
	protected void validate(Controller c) {
		validateRequiredString("broadband.name", "broadbandNameMessages", "业务名称不能为空");
		validateRequiredString("broadband.business_summary", "broadbandBusinessSummaryMessages", "业务简介不能为空");
		validateRequiredString("broadband.city", "broadbandCityMessages", "所属城市不能为空");
		if(StrKit.notBlank(c.getPara("broadband.price"))){
			validateRegex("broadband.price", "^\\d+$", "broadbandPriceMessages", "价格只能是纯数字");
		}
		this.setShortCircuit(true);
		validateRequiredString("broadband.order_num", "broadbandOrderNumMessages", "排序不能为空");
        validateRegex("broadband.order_num", "^\\d+$", "broadbandOrderNumMessages", "排序只能是纯数字");
	}

	@Override
	protected void handleError(Controller c) {
		c.keepModel(Broadband.class);
		c.render("/admin/broadband_add.html");
	}
}
